package com.demo.springboot;

import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.gson.GsonAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.HashMap;
import java.util.Map;

/***
 * -------------------SpringBootApplication---------------------------
 * @SpringBootApplication 默认扫描的路径是当前类的所在的包及其子包下的所有类，
 *
 *             1.可以通过 scanBasePackages 添加其他的包进行扫描
 *             2. exclude 排除指定的类或者配置类
 *
 *
 *  ------------------------------Banner--------------------------
 *  SpringApplication.setBannerMode(Banner.Mode.OFF) 关闭banner显示
 *  自定义Banner：
 *  文本：
 *  1. classpath 目录新建 banner.txt / 或者在application.properties中配置spring.banner.location=*.txt
 *  2. 通过网站：http://patorjk.com/software/taag  生成想要的图案
 *  3. 将生成的文本复制到banner.txt/*.txt
 *
 *  也支持图片(支持jpg,png,gif):
 *  1. classpath 目录复制 banner.jpg/png/gif
 *  也可以通过配置文件指定 spring.banner.image.location=*.jpg/png/gif
 *
 *
 *
 *  ------------------配置项默认值------------------------
 *  SpringApplication.setDefaultProperties(Map<String, Object> defaultProperties)
 *  SpringApplication.setDefaultProperties(Properties defaultProperties)
 *  为配置项指定默认值
 */
@SpringBootApplication(scanBasePackages = "com.demo",exclude = GsonAutoConfiguration.class)
public class App {

    @Value("${server.host:localhost}")
    private String serverHost;
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(App.class);
        Map<String,Object> defaultProperties = new HashMap<>();
        defaultProperties.put("server.host","192.168.1.1");
        app.setDefaultProperties(defaultProperties);
        //app.setBannerMode(Banner.Mode.OFF);
        ConfigurableApplicationContext context =  app.run(args);
        System.out.println(context.getBean(Runnable.class));
        //System.out.println(context.getBean(Gson.class));
        System.out.println(context.getEnvironment().getProperty("server.host","aaa"));
        System.out.println(context.getBean(App.class).serverHost);
        context.close();
    }
}
